<?php

namespace app\service\article;

use app\service\base\BaseLogic;

class ArticleCategoryLogic extends BaseLogic
{
    public function add($articleId, $categoryId)
    {
        $arrData = [
            'article_id' => $articleId,
            'category_id' => $categoryId,
        ];
        return (new ArticleCategoryModel())->add($arrData);
    }

    public function delByIds($articleId)
    {
        return (new ArticleCategoryModel())->delByArticleId($articleId);
    }

    public function getCateByArtId($articleId)
    {
        $arrWhere = [];
        $arrWhere[] = ['article_id', '=', $articleId];
        $arrData = (new ArticleCategoryModel())->getList($arrWhere, 'category_id');
        if (empty($arrData)) {
            return [];
        }
        return array_column($arrData, 'category_id');
    }
}